package com.wn26.shopczpro.servlet;

import java.io.IOException;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.wn26.shopczpro.service.UserService;
import com.wn26.shopczpro.service.UserServiceImpl;



/**
 * Servlet implementation class CheckTelExistsServlet
 * 
 * @WebServlet注解等同于在web.xml中配置一个Servlet
 * 		servlet-name的值就是当前类名
 * 		url-pattern就是参数
 */
@WebServlet(name = "checkTelExistsServlet",urlPatterns = {"/checkTelExists"})
public class CheckTelExistsServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public CheckTelExistsServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		try {
			//-- 1.获取手机号  获取请求参数
			String user_tel = request.getParameter("user_tel");
			
			//-- 2.调用Service
			UserServiceImpl usi = new UserServiceImpl();
			String result = "";
			try {
				if(usi.checkTelExists(user_tel) == false) {
					result = "Fail";
				}else{
					result = "OK";
				}
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			System.out.println("result:\t" + result);
			//-- 3.把结果写回前端
			response.getWriter().write(result);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}	
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
